package com.sloera.spring.temp;

import com.alibaba.fastjson.JSONObject;
import org.junit.Test;

import java.time.Duration;
import java.time.Instant;
import java.util.*;

/**
 * @file com.sloera.spring.temp.TESTtemp
 * @create 2020-5-9
 */
public class TESTtemp {
    @Test
    public void time() throws InterruptedException {
        Instant start = Instant.now();
        Thread.sleep(1000);
        Instant end = Instant.now();
        Duration duration = Duration.between(start, end);
        System.out.println(duration.toMillis() / (double) 1000 + "s");
        System.out.println(duration.toMinutes());

    }

    @Test
    public void time2() throws InterruptedException {
        long startL = new Date().getTime();
        Date start = new Date();
        Thread.sleep(1000);
        Date end = new Date();
        long endL = new Date().getTime();
        System.out.println("startL:" + startL + " endL:" + endL + " 执行时长:" + (endL - startL) / (double) 1000 + "秒");
        System.out.println("start:" + start + " end:" + end + " 执行时长:" + (end.getTime() - start.getTime()) / (double) 1000 + "秒");

    }

    @Test
    public void test3() {
        String receives = "[]";
        List<Map<String, Object>> phoneList = JSONObject.parseObject(receives, List.class);
        System.out.println(phoneList);
        System.out.println(phoneList.size());

    }

    @Test
    public void test4() {
        System.out.println(JSONObject.parseObject("{\"phone\":\"bbb\",\"phone1\":\"bbb2\"}", Map.class));
        List<Map<String, Object>> list = JSONObject.parseObject("[{\"phone\":\"bbb\",\"phone1\":\"bbb2\"},{\"phone\":\"bbb\",\"phone1\":\"bbb2\"}]", List.class);
        System.out.println(list);
        System.out.println(list.get(0).get("phone"));


        Map<String, Object> send = new HashMap<String, Object>();
        send.put("name", "aaa");
        send.put("phone", "bbb");
        System.out.println(send.toString());

        Map<String, Object> send2 = new HashMap<String, Object>();
        send2.put("name", "aaa1");
        send2.put("phone", "bbb1");
        List<Map<String, Object>> list2 = new ArrayList<>();
        list2.add(send);
        list2.add(send2);
        System.out.println(list2);
    }
}
